/*******************************************************************************
 * Copyright (c) 2008, 2009 Tapestry IDE Developers
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Tapestry IDE Developers - initial API and implementation
 *******************************************************************************/
package com.googlecode.tapestry.ide;

import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

import com.googlecode.tapestry.ide.core.ioc.IBeanFactory;
import com.googlecode.tapestry.ide.internal.core.ioc.BeanFactory;
import com.googlecode.tapestry.ide.ui.TapestryImages;

/**
 * Controls the plug-in life cycle.
 */
public class TapestryPlugin extends AbstractUIPlugin {

	/**
	 * Plugin identifier for Tapestry IDE plug-in (value
	 * <code>com.googlecode.tapestry.ide</code>).
	 */
	public static final String PLUGIN_ID = "com.googlecode.tapestry.ide";

	/**
	 * The identifier for the Tapestry nature (value
	 * <code>"com.googlecode.tapestry.ide.tapestryNature"</code>). The presence
	 * of this nature on a project indicates that it is Tapestry-capable.
	 */
	public static final String NATURE_ID = PLUGIN_ID + ".tapestryNature";

	/** The shared instance. */
	private static TapestryPlugin plugin;

	/**
	 * Returns the shared instance.
	 * 
	 * @return the shared instance
	 */
	public static final TapestryPlugin getDefault() {
		return plugin;
	}

	/** The bean factory. */
	private IBeanFactory beanFactory;

	/**
	 * The constructor.
	 */
	public TapestryPlugin() {
		plugin = this;
	}

	/**
	 * Gets the bean factory.
	 * 
	 * @return the bean factory
	 */
	public IBeanFactory getBeanFactory() {
		return beanFactory;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
	 * )
	 */
	@Override
	public void start(BundleContext context) throws Exception {
		super.start(context);
		beanFactory = new BeanFactory();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
	 * )
	 */
	@Override
	public void stop(BundleContext context) throws Exception {
		super.stop(context);
		beanFactory.shutdown();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ui.plugin.AbstractUIPlugin#initializeImageRegistry(org.eclipse
	 * .jface.resource.ImageRegistry)
	 */
	@Override
	protected void initializeImageRegistry(ImageRegistry registry) {
		TapestryImages.initializeImageRegistry(registry);
	}

}
